# include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const ll MAXN = 50;

inline char getc() {
    static char buf[1 << 18], *fs, *ft;
    return (fs == ft && (ft = (fs = buf) + fread(buf, 1, 1 << 18, stdin)), fs == ft) ? EOF : *fs++;
}

inline ll gn() {
    ll k = 0, f = 1;
    char c = getc();
    for(; !isdigit(c); c = getc()) if(c == '-') f = -1;
    for(; isdigit(c); c = getc()) k = k * 10 + c - '0';
    return k * f;
} 

ll a[MAXN], pre[MAXN], ans, n, m;

void dfs(ll x, ll y) {
    if(x > n || y > m) return;
    if(y == m) {
        printf("%lld\n", m);
        exit(0);
    }
    ans = max(ans, y);
    for(int i = x + 1; i <= n; i++) {
        if(y + pre[i] <= ans) break; 
        dfs(i, y + a[i]);
    }
}

int main() { 
# ifndef LOCAL 
    freopen("drink.in", "r", stdin);
    freopen("drink.out", "w", stdout);
# endif
    n = gn(), m = gn();
    for(int i = 1; i <= n; i++) a[i] = gn();
    for(int i = n; i >= 1; i--) pre[i] = pre[i + 1] + a[i];
    dfs(0, 0);
    printf("%lld\n", ans);
    return 0;
}
